package com.manuelvs.bobbysadventure;

import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;

public class configuration extends Activity {
	
    private Titular[] datos = 
        	new Titular[]
    		{
        		new Titular("More apps" , "See more apps from developer"),
        		new Titular("Bobby\'s version:" , "1.4"),
    		};
     char lofgjergo9igdf=0;
     Boolean usesjoystick=true;
     
    @Override
    public void onCreate(Bundle savedInstanceState) 
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.configuration);
        AdaptadorTitulares adaptador = new AdaptadorTitulares(this);
        final CheckBox checkBox = (CheckBox) findViewById(R.id.list_checkbox);
        ListView lstOpciones = (ListView)findViewById(R.id.listView1);
        SharedPreferences Joystick =
       	     getSharedPreferences("Joystick",Context.MODE_PRIVATE);
        final SharedPreferences.Editor editor = Joystick.edit();
        usesjoystick = Joystick.getBoolean("Joystick", true);
        
        if(usesjoystick) checkBox.setChecked(true);
        else checkBox.setChecked(false);
        
        lstOpciones.setTextFilterEnabled(true);

        lstOpciones.setAdapter(adaptador);
        
        lstOpciones.setOnItemClickListener(new OnItemClickListener() 
        {
        	//////////////////////
            public void onItemClick(AdapterView<?> parent, View view,int position, long id) 
            {
            	if(position==0)
            	{
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/developer?id=ManuelVS"));
                	startActivity(browserIntent);
            	}
            	if(position==1)
            	{
            		if(lofgjergo9igdf==5);
            		lofgjergo9igdf++;
            	}
            
            }
            //////////////////////
        });
        checkBox.setOnCheckedChangeListener(
    	    new CheckBox.OnCheckedChangeListener() {
				@Override
				public void onCheckedChanged(CompoundButton arg0,boolean arg1) 
				{
		            if (checkBox.isChecked()) 
		            {
		            	editor.putBoolean("Joystick", true);
		            	editor.commit();
		            }
		            else 
		            {
		            	editor.putBoolean("Joystick", false);
		            	editor.commit();
		            }
			}
    	});
    }
    
    class AdaptadorTitulares extends ArrayAdapter 
    {
    	
    	Activity context;
    	
    	AdaptadorTitulares(Activity context) 
    	{
    		super(context, R.layout.listexpandable, datos);
    		this.context = context;
    	}
    	
    	public View getView(int position, View convertView, ViewGroup parent)
    	{
			LayoutInflater inflater = context.getLayoutInflater();
			View item = inflater.inflate(R.layout.listexpandable, null);
			
			TextView lblTitulo = (TextView)item.findViewById(R.id.LblTitulo);
			lblTitulo.setText(datos[position].getTitulo());
			
			TextView lblSubtitulo = (TextView)item.findViewById(R.id.LblSubTitulo);
			lblSubtitulo.setText(datos[position].getSubtitulo());	
			

			return(item);
		}
    }
}